﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Http;
using Aliyun.Acs.Core.Profile;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.WebApi.Client;
using Newtonsoft.Json.Linq;
using SDWXServer.KD;
using SDWXServer.Models;

namespace SDWXServer.Controllers
{
    /// <summary>
    /// 授权验证
    /// </summary>
    public class UserController : ApiController
    {
        static TimeSpan _redisExpireInTimeSpan = new TimeSpan(30, 0, 0, 0);

        /// <summary>
        /// 验证UserToken是否有效
        /// </summary>
        /// <param name="userToken">用户令牌</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult ValidateToken(string userToken)
        {
            var result = new WebApiResult();
            result.Successful = true;
            result.Data["UserToken"] = "";
            result.Data["UnionID"] = "";

            try
            {
                if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("UserToken为空");

                var user = RedisManager.GetObject<WXUser>(userToken);
                if (user == null) throw new Exception(string.Format("无效的userToken:{0}", userToken));

                result.Data["UserToken"] = user.Id;
                result.Data["UnionID"] = user.UnionID;

                Action action = () =>
                {
                    try
                    {
                        user.DateTime = DateTime.Now;
                        GetRoles(user);
                        RedisManager.SetObject<WXUser>(user);
                    }
                    catch { }
                };
                Kingdee.BOS.KDThread.MainWorker.QuequeTask(action, (asynResult) => { });
            }
            catch (Exception e)
            {
                result.Successful = false;
                result.Message = e.Message;

                Logger.Error("ValidateToken", e);
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// 验证授权
        /// </summary>
        /// <param name="userToken">用户令牌</param>
        /// <param name="wxCode">小程序授权Code</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult Validate(string userToken, string wxCode)
        {
            var result = new WebApiResult();
            result.Successful = true;
            result.Data["UserToken"] = "";

            try
            {
                var wxRet = WXService.Getjscode2session(wxCode);
                if (wxRet.errcode == Senparc.Weixin.ReturnCode.请求成功)
                {
                    var openId = wxRet.openid;
                    var unionId = wxRet.unionid;
                    var sessionKey = wxRet.session_key;
                    //使用SessionContainer管理登录信息（推荐）
                    Senparc.Weixin.WxOpen.Containers.SessionContainer.UpdateSession(sessionKey, openId, sessionKey, unionId);

                    userToken = RedisManager.GetValue<string>(openId);
                    if (string.IsNullOrWhiteSpace(userToken))
                    {
                        userToken = Guid.NewGuid().ToString();
                    }
                    var user = RedisManager.GetObject<WXUser>(userToken);

                    if (string.IsNullOrWhiteSpace(unionId) == false)
                    {
                        var mpToken = RedisManager.GetValue<string>(unionId);
                        var mpUser = RedisManager.GetObject<WXUser>(mpToken);
                        if (user == null)
                        {
                            user = mpUser;
                        }
                        else
                        {
                            if (mpUser != null)
                            {
                                user.MPOpenId = mpUser.MPOpenId;
                            }
                        }
                    }

                    if (user == null)
                    {
                        user = new WXUser();
                        user.Id = Guid.NewGuid().ToString();
                    }

                    user.DateTime = DateTime.Now;
                    user.OpenId = openId;
                    user.SessionKey = sessionKey;
                    user.UnionID = unionId;

                    result.Data["UserToken"] = user.Id;
                    result.Data["UnionID"] = user.UnionID;

                    RedisManager.SetObject<WXUser>(user);
                    RedisManager.SetValue<string>(user.OpenId, user.Id);
                    if (string.IsNullOrWhiteSpace(user.PhoneNumber) == false)
                    {
                        RedisManager.SetValue<string>(user.PhoneNumber, user.Id);
                    }
                    if (string.IsNullOrWhiteSpace(user.UnionID) == false)
                    {
                        RedisManager.SetValue<string>(user.UnionID, user.Id);
                    }
                }
                else
                {
                    result.ExceptionCode = wxRet.errcode.ToString();
                    result.Message = wxRet.errmsg;
                    result.Successful = false;
                }
            }
            catch (Exception e)
            {
                result.Successful = false;
                result.Message = e.Message;

                Logger.Error("Validate", e);
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// 手机号码+验证码登录
        /// </summary>
        /// <param name="phoneNumber">手机号码</param>
        /// <param name="code">验证码</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult ValidateCode(string phoneNumber, string code)
        {
            var result = new WebApiResult();
            result.Successful = true;
            result.Message = "";
            result.Data["UserToken"] = "";

            try
            {
                if (string.IsNullOrWhiteSpace(phoneNumber)) throw new Exception("手机号码不允许为空");
                if (string.IsNullOrWhiteSpace(code)) throw new Exception("验证码不允许为空");

                var wxValidateCode = RedisManager.GetObject<WXValidateCode>(phoneNumber);
                if (wxValidateCode == null) throw new Exception("请首先为当前手机号码生成验证码");
                if (wxValidateCode.Code != code) throw new Exception("无效的验证码");
                if (wxValidateCode.ExpiryDate < DateTime.Now) throw new Exception("验证码已失效");

                WXUser user = null;
                var userToken = RedisManager.GetValue<string>(phoneNumber);
                if (string.IsNullOrWhiteSpace(userToken) == false)
                {
                    user = RedisManager.GetObject<WXUser>(userToken);
                }
                if (user == null)
                {
                    user = new WXUser();
                    user.Id = Guid.NewGuid().ToString();
                    user.PhoneNumber = phoneNumber;

                    RedisManager.SetValue<string>(phoneNumber, user.Id);
                    RedisManager.SetObject<WXUser>(user);
                }

                result.Data["UserToken"] = user.Id;
            }
            catch (Exception e)
            {
                result.Successful = false;
                result.Message = e.Message;

                Logger.Error("Validate", e);
            }

            return Json<WebApiResult>(result);
        }
        void GetRoles(WXUser user)
        {
            if (string.IsNullOrWhiteSpace(user.PhoneNumber)) return;

            user.IsAdministrator = LoginViewModel.Current.AdministratorMobile.Contains(user.PhoneNumber);
            user.YuYueTime = LoginViewModel.Current.YuYueTime;

            #region 金蝶云登录验证
            LoginViewModel.CheckLogin();
            if (LoginViewModel.Current.LoginSuccessful == false)
            {
                throw new Exception("金蝶云登录失败");
            }
            #endregion


            var userInfos = GetUserInfos(user.PhoneNumber);
            if (userInfos.Count > 0)
            {
                var userobj = userInfos[0] as DynamicObject;
                user.ERPUserId = Convert.ToInt64(userobj["FUSERID"]);
                user.ERPUserName = Convert.ToString(userobj["FNAME"]);
            }



            var empInfos = GetEmpInfos(user.PhoneNumber);
            if (empInfos.Count > 0)
            {
                var empInfo = empInfos[0] as DynamicObject;
                user.EmpId = Convert.ToInt64(empInfo["FID"]);
                user.EmpName = Convert.ToString(empInfo["FNAME"]);
            }
            //else
            //{
            //    throw new Exception("手机号码未注册为ERP用户，或用户已被禁用");
            //}
            //var retKD = client.ExecuteDynamicObject()
            //var wrzs = new SD.WRZS.K3.ServiceFacade.KDServiceClient.WRZSClientProxy();
            //var retKD = wrzs.GetUserInfoByMobilePhone(user.PhoneNumber);
            //if (retKD.Successful == false) throw new Exception(retKD.Message);

            //user.IsDriver = Convert.ToBoolean(retKD.Result["IsDriver"]);
            //user.IsCustomer = Convert.ToBoolean(retKD.Result["IsCustomer"]);
            //user.IsSupplier = Convert.ToBoolean(retKD.Result["IsSupplier"]);
            //user.IsStocker = retKD.Result.GetValue<bool>("IsStocker", false);

            //user.CustomerIDs.Clear();
            //user.SupplierIDs.Clear();
            //user.StockIDs.Clear();
            //var customerIDs = retKD.Result.GetValue<Kingdee.BOS.JSON.JSONArray>("CustomerIDs", new Kingdee.BOS.JSON.JSONArray());
            //user.CustomerIDs.AddRange(customerIDs.Select(p => Convert.ToInt64(p)));
            //var supplierIDs = retKD.Result.GetValue<Kingdee.BOS.JSON.JSONArray>("SupplierIDs", new Kingdee.BOS.JSON.JSONArray());
            //user.SupplierIDs.AddRange(supplierIDs.Select(p => Convert.ToInt64(p)));
            //var stockIDs = retKD.Result.GetValue<Kingdee.BOS.JSON.JSONArray>("StockIDs", new Kingdee.BOS.JSON.JSONArray());
            //user.StockIDs.AddRange(stockIDs.Select(p => Convert.ToInt64(p)));
        }
        /// <summary>
        /// 获取手机验证码
        /// </summary>
        /// <param name="phoneNumber">手机号码</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult GetValidateCode(string phoneNumber)
        {
            var result = new WebApiResult();
            result.Successful = true;
            result.Message = "已成功发送验证码";

            try
            {
                if (string.IsNullOrWhiteSpace(phoneNumber)) throw new Exception("手机号码不允许为空");

                var preFix = "D37D37BD-E7E7-493A";
                var lastFix = "-B23E-B6347504E4AE";
                if (phoneNumber.StartsWith(preFix) == false)
                {
                    throw new Exception("手机号码不合法");
                }
                if (phoneNumber.EndsWith(lastFix) == false)
                {
                    throw new Exception("手机号码不合法");
                }
                phoneNumber = phoneNumber.Replace(preFix, "").Replace(lastFix, "");

                var code = RedisManager.GetObject<WXValidateCode>(phoneNumber);
                if (code == null) code = new WXValidateCode();
                code.Id = phoneNumber;
                code.SetNewCode();
                var span = DateTime.Now - code.SendTime;
                if (span.TotalSeconds < 60) throw new Exception("禁止操作：发送验证码太频繁，请间隔1分钟再尝试");

                var smsSignName = "车辆预约登记";
                var smsSignNameObj = System.Configuration.ConfigurationManager.AppSettings.Get("SMSSignName");
                if (smsSignNameObj != null) smsSignName = Convert.ToString(smsSignNameObj);

                SendSMSForValidateCode(phoneNumber, code.Code, smsSignName);

                code.SendTime = DateTime.Now;
                RedisManager.SetObject<WXValidateCode>(code, _redisExpireInTimeSpan);
            }
            catch (Exception e)
            {
                result.Successful = false;
                result.Message = e.Message;

                Logger.Error("GetValidateCode", e);
            }

            return Json<WebApiResult>(result);
        }

        /// <summary>
        /// 解密微信用户手机号
        /// </summary>
        /// <param name="phoneInfo"></param>
        /// <returns></returns>
        [HttpPost]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult Phone([FromBody] UserPhoneParam phoneInfo)
        {
            var result = new WebApiResult();
            result.Data["phoneNumber"] = "";

            try
            {
                if (phoneInfo == null)
                {
                    throw new Exception("参数phoneInfo不允许为空");
                }

                var userToken = phoneInfo.UserToken;
                var encryptedData = phoneInfo.EncryptedData;
                var iv = phoneInfo.IV;
                if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("userToken不允许为空");

                var user = RedisManager.GetObject<WXUser>(userToken);
                if (user == null) throw new Exception("userToken无效");

                var dataStr = WXService.DecryptPhoneNumber(user.SessionKey, encryptedData, iv);
                result.Data["phoneNumber"] = dataStr.phoneNumber;
                result.Successful = true;

                user.PhoneNumber = dataStr.phoneNumber;
                var oldUserToken = RedisManager.GetValue<string>(user.PhoneNumber);
                if (string.IsNullOrWhiteSpace(oldUserToken) == false)
                {
                    var oldUser = RedisManager.GetObject<WXUser>(oldUserToken);
                    if (oldUser != null)
                    {
                        if (oldUser.Id != user.Id)
                        {
                            user.IDCardNo = oldUser.IDCardNo;
                            user.Plate = oldUser.Plate;
                            user.Name = oldUser.Name;
                            user.TruckTypeId = oldUser.TruckTypeId;
                            user.TruckTypeName = oldUser.TruckTypeName;

                            var oldKey = string.Format("{0}_Voiture", oldUser.Id);
                            var lstWXVoiture = RedisManager.GetValue<List<WXVoiture>>(oldKey);
                            if (lstWXVoiture == null)
                            {
                                lstWXVoiture = new List<WXVoiture>();
                            }
                            var newKey = string.Format("{0}_Voiture", user.Id);
                            RedisManager.SetValue<List<WXVoiture>>(newKey, lstWXVoiture);
                        }
                    }
                }
                user.DateTime = DateTime.Now;
                GetRoles(user);

                RedisManager.SetObject<WXUser>(user);
                if (string.IsNullOrWhiteSpace(user.PhoneNumber) == false)
                {
                    RedisManager.SetValue<string>(user.PhoneNumber, user.Id);
                }
            }
            catch (Exception e)
            {
                result.HandleWSException(e);
                Logger.Error("Phone", e);
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// 解密微信用户信息
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        [HttpPost]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult UnionID([FromBody] UserPhoneParam userInfo)
        {
            var result = new WebApiResult();
            try
            {
                if (userInfo == null)
                {
                    throw new Exception("参数userInfo不允许为空");
                }

                var userToken = userInfo.UserToken;
                var encryptedData = userInfo.EncryptedData;
                var iv = userInfo.IV;
                if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("userToken不允许为空");

                var user = RedisManager.GetObject<WXUser>(userToken);
                if (user == null) throw new Exception("userToken无效");

                var dataStr = WXService.DecodeUserInfoBySessionId(user.SessionKey, encryptedData, iv);
                user.UnionID = dataStr.unionId;
                result.Data["UnionID"] = user.UnionID;
                result.Successful = true;

                RedisManager.SetObject<WXUser>(user);
                if (string.IsNullOrWhiteSpace(user.UnionID) == false)
                {
                    RedisManager.SetValue<string>(user.UnionID, user.Id);
                }
            }
            catch (Exception e)
            {
                result.HandleWSException(e);
                Logger.Error("UnionID", e);
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userToken">用户令牌</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult GetUserInfo(string userToken)
        {
            var result = new WebApiResult();
            result.Successful = true;

            try
            {
                if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("userToken不允许为空");

                var user = RedisManager.GetObject<WXUser>(userToken);
                if (user == null) throw new Exception("userToken无效");

                result.Successful = true;
                result.Data = JObject.FromObject(user);
            }
            catch (Exception e)
            {
                result.Successful = false;
                result.Message = e.Message;
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// 设置用户信息
        /// </summary>
        /// <param name="userInfo">用户信息结构</param>
        /// <returns></returns>
        [HttpPost]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult SetUserInfo([FromBody] UserParam userInfo)
        {
            var result = new WebApiResult();
            try
            {
                if (userInfo == null)
                {
                    throw new Exception("参数param不允许为空");
                }

                var userToken = userInfo.UserToken;
                var name = userInfo.Name;
                var idCardNo = userInfo.IDCardNo;
                var plate = userInfo.Plate;
                var truckType = userInfo.TruckTypeId;
                if (string.IsNullOrWhiteSpace(truckType))
                {
                    truckType = "555aa682e1c2c7";
                }
                if (string.IsNullOrWhiteSpace(userToken)) throw new Exception("userToken不允许为空");

                var user = RedisManager.GetObject<WXUser>(userToken);
                if (user == null) throw new Exception("userToken无效");

                user.Name = name;
                user.IDCardNo = idCardNo;
                user.Plate = plate;
                user.TruckTypeId = truckType;
                user.TruckTypeName = WXPCD.GetTruckTypeName(user.TruckTypeId);
                RedisManager.SetObject<WXUser>(user);

                result.Successful = true;
            }
            catch (Exception e)
            {
                result.HandleWSException(e);
            }

            return Json<WebApiResult>(result);
        }
        /// <summary>
        /// WebApi Execute Service
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        [HttpPost]
        [ResponseType(typeof(WebApiResult))]
        public IHttpActionResult Execute([FromBody] ExecuteParam param)
        {
            object data = null;

            try
            {
                if (param == null)
                {
                    throw new Exception("参数param不允许为空");
                }

                if (string.IsNullOrWhiteSpace(param.UserToken)) throw new Exception("userToken不允许为空");
                if (string.IsNullOrWhiteSpace(param.ServiceName)) throw new Exception("ServiceName不允许为空");
                if (param.Parameters == null) param.Parameters = new List<object>();
                param.ServiceName = param.ServiceName.Replace(".common.kdsvc", "");

                var user = RedisManager.GetObject<WXUser>(param.UserToken);
                if (user == null) throw new Exception("userToken无效");

                #region 金蝶云登录验证
                if (string.IsNullOrWhiteSpace(LoginViewModel.Current.ApiClientUserToken) == false)
                {
                    var loginContextStr = LoginViewModel.Current.ApiClient.Execute<string>("Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUserToken", new object[] { LoginViewModel.Current.ApiClientUserToken });
                    var loginContext = Kingdee.BOS.JSON.JSONObject.Parse(loginContextStr, new Kingdee.BOS.JSON.JSONObject());
                    if (loginContext == null) loginContext = new Kingdee.BOS.JSON.JSONObject();
                    LoginViewModel.Current.ApiClientUserToken = loginContext.GetValue<string>("UserToken", "");
                    if (string.IsNullOrWhiteSpace(LoginViewModel.Current.ApiClientUserToken))
                    {
                        LoginViewModel.Current.ApiClientUserToken = "";
                    }
                }
                if (string.IsNullOrWhiteSpace(LoginViewModel.Current.ApiClientUserToken) == true)
                {
                    Logger.Info("开始登录金蝶云ApiClient");
                    var loginResultStr = LoginViewModel.Current.ApiClient.ValidateLogin(LoginViewModel.Current.DataCenterId, LoginViewModel.Current.User, LoginViewModel.Current.Password, 2052);
                    var loginResult = Kingdee.BOS.JSON.JSONObject.Parse(loginResultStr, new Kingdee.BOS.JSON.JSONObject());
                    var loginContext = loginResult.GetValue<Kingdee.BOS.JSON.JSONObject>("Context", new Kingdee.BOS.JSON.JSONObject());
                    if (loginContext == null) loginContext = new Kingdee.BOS.JSON.JSONObject();
                    LoginViewModel.Current.ApiClientUserToken = loginContext.GetValue<string>("UserToken", "");
                    if (string.IsNullOrWhiteSpace(LoginViewModel.Current.ApiClientUserToken))
                    {
                        Logger.Info("失败登录金蝶云ApiClient");
                    }
                    else
                    {
                        Logger.Info(string.Format("成功登录金蝶云ApiClient:{0}", LoginViewModel.Current.ApiClientUserToken));
                    }
                }
                #endregion

                var resultAPI = LoginViewModel.Current.ApiClient.Execute<object>(param.ServiceName, param.Parameters.ToArray());

                if (data == null)
                {
                    try
                    {
                        data = JObject.Parse(resultAPI.ToString());
                    }
                    catch { }
                }
                if (data == null)
                {
                    try
                    {
                        data = JObject.FromObject(resultAPI);
                    }
                    catch { }
                }
                if (data == null)
                {
                    try
                    {
                        data = JArray.Parse(resultAPI.ToString());
                    }
                    catch { }
                }
                if (data == null)
                {
                    try
                    {
                        data = JArray.FromObject(resultAPI);
                    }
                    catch { }
                }

                if (data == null)
                {
                    try
                    {
                        data = new JValue(resultAPI);
                    }
                    catch { }
                }
            }
            catch (Exception e)
            {
                data = e.Message;
            }

            return Json<object>(data);
        }

        private void SendSMSForValidateCode(string phoneNumber, string code, string signName)
        {
            var templateParam = new Kingdee.BOS.JSON.JSONObject();
            templateParam["code"] = code;

            IClientProfile profile = DefaultProfile.GetProfile("", "LTAI4FnNXLRYqfVUZgKNCSFk", "ctsjJZJM8hwfxhh6k5VwUS4RjWv9zT");
            DefaultAcsClient client = new DefaultAcsClient(profile);
            CommonRequest request = new CommonRequest();
            request.Method = MethodType.POST;
            request.Domain = "dysmsapi.aliyuncs.com";
            request.Version = "2017-05-25";
            request.Action = "SendSms";
            // request.Protocol = ProtocolType.HTTP;
            request.AddQueryParameters("PhoneNumbers", phoneNumber);
            request.AddQueryParameters("SignName", signName);
            request.AddQueryParameters("TemplateCode", "SMS_199315093");
            request.AddQueryParameters("TemplateParam", templateParam.ToString());

            CommonResponse response = client.GetCommonResponse(request);
            var resultStr = System.Text.Encoding.UTF8.GetString(response.HttpResponse.Content);
            var resultJson = Kingdee.BOS.JSON.JSONObject.Parse(resultStr, new Kingdee.BOS.JSON.JSONObject());
            var resultCodeIsOK = resultJson.GetValue<string>("Code", "") == "OK";
            var resultMessage = resultJson.GetValue<string>("Message", "");
            if (resultCodeIsOK == false) throw new Exception(resultMessage);
        }

        DynamicObjectCollection GetEmpInfos(string phone)
        {
            DynamicObjectCollection objs = null;
            var sql = string.Format(@"
SELECT T1.FID,T2.FNAME
FROM T_HR_EMPINFO T1
INNER JOIN T_HR_EMPINFO_L T2 ON T2.FID=T1.FID AND T2.FLOCALEID=2052
WHERE  T1.FFORBIDSTATUS='A' AND T1.FMobile=@Phone
");

            var lst = new List<Kingdee.BOS.SqlParam>();
            lst.Add(new Kingdee.BOS.SqlParam("@Phone", Kingdee.BOS.KDDbType.String, phone));
            var client = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
            objs = client.ExecuteDynamicObject(sql, System.Data.CommandType.Text, lst);

            return objs;
        }

        DynamicObjectCollection GetUserInfos(string phone)
        {
            DynamicObjectCollection objs = null;
            var sql = string.Format(@"
SELECT FUSERID,FNAME FROM T_SEC_USER
WHERE FFORBIDSTATUS='A' AND FPHONE=@Phone
");

            var lst = new List<Kingdee.BOS.SqlParam>();
            lst.Add(new Kingdee.BOS.SqlParam("@Phone", Kingdee.BOS.KDDbType.String, phone));
            var client = new SD.MSXZ.K3.ServiceFacade.KDServiceClient.MSXZClientProxy();
            objs = client.ExecuteDynamicObject(sql, System.Data.CommandType.Text, lst);

            return objs;
        }
    }

    /// <summary>
    /// 用户信息结构
    /// </summary>
    public class UserParam
    {
        /// <summary>
        /// 用户令牌
        /// </summary>
        public string UserToken { get; set; }
        /// <summary>
        /// 身份证号
        /// </summary>
        public string IDCardNo { get; set; }
        /// <summary>
        /// 车牌号
        /// </summary>
        public string Plate { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 车辆类型
        /// </summary>
        public string TruckTypeId { get; set; }
    }
    /// <summary>
    /// 用户、手机加密数据结构
    /// </summary>
    public class UserPhoneParam
    {
        /// <summary>
        /// 用户令牌
        /// </summary>
        public string UserToken { get; set; }
        /// <summary>
        /// 加密数据
        /// </summary>
        public string EncryptedData { get; set; }
        /// <summary>
        /// IV
        /// </summary>
        public string IV { get; set; }
    }
    /// <summary>
    /// ExecuteParam
    /// </summary>
    public class ExecuteParam
    {
        public ExecuteParam()
        {
            this.Parameters = new List<object>();
        }
        /// <summary>
        /// 用户令牌
        /// </summary>
        public string UserToken { get; set; }
        /// <summary>
        /// API名称
        /// </summary>
        public string ServiceName { get; set; }
        /// <summary>
        /// API参数
        /// </summary>
        public List<object> Parameters { get; set; }
    }
}